home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / MaximizeConsoleHeight.c < prev    next >
Text File  |  1995-08-13  |  5KB  |  119 lines

  1. /*
  2. MaximizeConsoleHeight.c
  3. Both THINK C and Metrowerks CodeWarrior C provide a built-in console for stdin
  4. and stdout. That console is less useful than it might be because it opens to
  5. only a small size, presumably designed to fit on the tiny screen of a Mac Plus,
  6. i.e. the lowest common denominator, for portability. MaximizeConsoleHeight
  7. requests that the console open to the full height of your main screen. This
  8. makes good use of your screen, while maintaining the portability of your
  9. application. Call MaximizeConsoleHeight() BEFORE opening the console, i.e.
  10. before your first printf().
  11.  
  12. To set the WIDTH of the THINK C console, before opening it, do this:
  13.     #include <console.h>
  14.     ...
  15.     console_options.ncols=100;
  16.  
  17. To set the width of the CodeWarrior console, before opening it, do this:
  18.     #include <SIOUX.h>
  19.     ...
  20.     tSIOUXSettings.columns=100;
  21. Incidentally, VideoToolbox.h includes both THINK C's console.h and CodeWarrior's SIOUX.h,
  22. so you can omit the #include statements if you're already including VideoToolbox.h.
  23.  
  24. LIMITATION:
  25. In June 1994 Mike Garver reported that on a Mac Plus running System 6.07 with an
  26. attached big screen the console window appears on the Mac Plus screen, as it
  27. should, but extends well past the bottom, "so I could see none of the text
  28. unless I moved the window onto the large screen." This happens because, when
  29. Color QuickDraw is not available, MaximizeConsoleHeight() resorts to using the
  30. CrsrPin rect to estimate the height of the main screen. (CrsrPin is the
  31. rectangle to which the cursor is confined. When the desktop isn't rectangular
  32. CrsrPin is the smallest rectangle that contains the desktop.) I don't know how
  33. to fix this. If Color QuickDraw were running then the program would have
  34. correctly gotten the bounds of the main device, but the computer lacks Color
  35. QuickDraw, so there are no video device records, nor a GrayRgn structure to
  36. consult. Since MaximizeConsoleHeight() is typically called before QuickDraw is
  37. initialized we can't use qd.screenBits.bounds (which is probably the same as
  38. CrsrPin rect anyway). I can't think of any way for this program to find out the
  39. correct height of the main screen under these circumstances. So I blame this on
  40. the necessary cludge implicit in having two screens in a computer lacking Color
  41. QuickDraw, since 1-bit QuickDraw doesn't really support multiple screens. I
  42. believe, but didn't confirm, that System 7 provides 32-bit QuickDraw (which
  43. includes Color QuickDraw) on all computers.
  44.  
  45. HISTORY:
  46. 1/92    dgp wrote it.
  47. 8/27/92    dgp    check for 8-bit quickdraw before using GDevices.
  48. 10/10/92 dgp Reduced maximum console height by one pixel, so as not to clip 
  49.             displayed text.
  50. 2/22/93    dgp replaced GetMBarHeight() by MBarHeight.
  51. 4/16/93    dgp    enhanced to actively support 1-bit QD, rather than doing nothing.
  52. 6/3/94    dgp    replaced low-memory global MBarHeight by GetMBarHeight().
  53. 6/21/94 dgp documented limitation above.
  54. 6/28/94 dgp use gdRect instead of pixmap bounds, which is correct for any device,
  55. not just the main device.
  56. 10/10/94 dgp added support for Metrowerks CodeWarrior C.
  57. 11/17/94 dgp Eliminated need for THINK C's LoMem.h by defining LMGetCrsrPin().
  58. 1/7/95 dgp updated to CW5, so that it now works similarly for both THINK & CW C.
  59. */
  60. #include "VideoToolbox.h"
  61. #if UNIVERSAL_HEADERS
  62.     #include <LowMem.h>
  63. #else
  64.     #define LMGetMBarHeight() (* (short *) 0x0BAA)
  65.     #define LMSetMBarHeight(MBarHeightValue) ((* (short *) 0x0BAA) = (MBarHeightValue))
  66. #endif
  67. // NOTE: Apple's Universal Headers fail to provide any access to CrsrPin, so I rolled my own.
  68. #define LMGetCrsrPin() (* (Rect *) 0x834)
  69.  
  70. void MaximizeConsoleHeight(void)
  71. {
  72.     long qD;
  73.     Rect r;
  74.     
  75.     Gestalt(gestaltQuickdrawVersion,&qD);
  76.     if(qD>=gestalt8BitQD) r=(*GetMainDevice())->gdRect;
  77.     else r=LMGetCrsrPin();    // Can't use qd.screenBits.bounds 'cause qd may not yet be inited.
  78.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  79.         console_options.top=LMGetMBarHeight()+19;    // allow for menu bar and title bar
  80.         console_options.left=1;
  81.         console_options.nrows=r.bottom-4-console_options.top;
  82.         console_options.nrows/=console_options.txSize*4/3-1; /* estimate line spacing */
  83.     #endif
  84.     #if __MWERKS__
  85.         SIOUXSettings.toppixel=LMGetMBarHeight()+19;    // allow for menu bar and title bar
  86.         SIOUXSettings.leftpixel=1;
  87.         SIOUXSettings.rows=r.bottom-4-SIOUXSettings.toppixel;
  88.         SIOUXSettings.rows/=SIOUXSettings.fontsize*4/3-1; /* estimate line spacing */
  89.  
  90.         // These settings approximate the behavior of the THINK C console.
  91.         SIOUXSettings.autocloseonquit=0;
  92.         SIOUXSettings.showstatusline=0;
  93.         SIOUXSettings.asktosaveonclose=0;
  94.     #endif
  95.     #if 0 && __MWERKS__
  96.         /*
  97.             This code probably fails under CW 5.5. The GetPort returns a window pointer
  98.             presumably corresponding to the console, 
  99.             but subsequent attempts to use that window pointer crash, e.g. in SetWTitle.
  100.             I reported the bug to Metrowerks.
  101.         */
  102.         Rect r;
  103.         GDHandle device;
  104.         WindowPtr window;
  105.     
  106.         printf("\n");
  107.         GetPort(&window);
  108.         device=GetWindowDevice(window);
  109.         if(device==NULL)return;
  110.         r=(**device).gdRect;
  111.         if(GetMainDevice()==device)r.top+=LMGetMBarHeight();
  112.         r.top+=19;        // allow for title bar
  113.         r.bottom-=1;    // allow for 1-pixel frame
  114.         r.left+=1;        // allow for 1-pixel frame
  115.         if(r.right-r.left>500)r.right=r.left+500;
  116.     //    SizeWindow(window,r.right-r.left,r.bottom-r.top,1);
  117.         MoveWindow(window,r.left,r.top,1);
  118.     #endif
  119. }